<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     pagizer
 * @subpackage  users
 */

class m_users_actions_ajaxGetUserGroupAction extends m_backoffice_extends_Action
{
	public function execute()
	{
		$q = $this->getRequestParameter("q");

		if(!$q)
		{
			return '';
		}
		
		$documentProvider = f_document_Provider::getInstance();
		$login = $documentProvider->loadDocuments("modules_users/user")
                ->orLike('login', '%'.$q.'%')
                ->orLike('firstname', '%'.$q.'%')
                ->orLike('lastname', '%'.$q.'%')
                ->limit(10)
                ->retrieveDocuments();

		foreach ($login as $data)
		{
            $value = $data->getUniqueId()."|".$data->getLogin();

            if($data->getFirstName() != "" || $data->getLastName() != "")
            {
                $value .= " (";
                if($data->getFirstName() != "")
                {
                    $value .= $data->getFirstName() . "r ";
                }

                if($data->getLastName() != "")
                {
                    $value .= $data->getLastName();
                }

                $value = rtrim($value);
                $value .= ")";
            }

            $value .= "\n";
            echo $value;
		}

	}	
}